package com.invengo.module_check.data.repsitory.business;

import android.annotation.SuppressLint;

import com.invengo.library_db.entity.module_check.BookBean;
import com.invengo.library_db.entity.module_check.BookCarBean;
import com.invengo.library_db.entity.module_check.RecordBean;
import com.invengo.library_db.entity.module_check.ShelfBean;
import me.goldze.mvvmhabit.http.UpdateResult;

import com.invengo.library_db.entity.module_check.StructBean;
import com.invengo.module_check.data.repsitory.business.source.BusinessSource;
import com.invengo.module_check.data.repsitory.business.source.impl.HttpBusinessSourceImpl;
import com.invengo.module_check.data.repsitory.business.source.impl.LocalBusinessSourceImpl;

import java.util.List;

import io.reactivex.Observable;
import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.bus.SourceUtils;
import me.goldze.mvvmhabit.http.BaseBean;

//实现代理类
public class BusinessRepsitory extends BaseModel<BusinessSource> implements BusinessSource {
    private volatile static BusinessRepsitory INSTANCE = null;

    public static BusinessRepsitory getInstance() {
        if (INSTANCE == null) {
            synchronized (BusinessRepsitory.class) {
                if (INSTANCE == null) {
                    INSTANCE = new BusinessRepsitory();
                }
            }
        }
        return INSTANCE;
    }

    @Override
    public void refreshSource() {
        source = SourceUtils.getSource(LocalBusinessSourceImpl.class, HttpBusinessSourceImpl.class);
    }

    @Override
    public void removeByBooks(List<BookBean> bookBeans) {
        source.removeByBooks(bookBeans);
    }

    @Override
    public Observable<BaseBean<BookBean>> getBookByTid(String tid) {
        return source.getBookByTid(tid);
    }

    @Override
    public Observable<BaseBean<BookBean>> getBookByCode(String code) {
        return source.getBookByCode(code);
    }

    @Override
    public Observable<BaseBean<ShelfBean>> getShelfInfoByCode(String shelfCode) {
        return source.getShelfInfoByCode(shelfCode);
    }

    @Override
    public Observable<BaseBean<ShelfBean>> getShelfInfoByTid(String tid) {
        return source.getShelfInfoByTid(tid);
    }

    @Override
    public Observable<BaseBean<ShelfBean>> getNextOrUpperShelf(String shelfCode, boolean isNext) {
        return source.getNextOrUpperShelf(shelfCode, isNext);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> forceRevokeBook(List<BookBean> bookBeans) {
        return source.forceRevokeBook(bookBeans);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> forcePositioning(List<BookBean> bookBeans, String shelfCode, String shelfName) {
        return source.forcePositioning(bookBeans, shelfCode, shelfName);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> bookListing(List<BookBean> bookBeans,String shelfCode,String ShelfName) {
        for (BookBean bookBean : bookBeans) {
            bookBean.setShelfCode(shelfCode);
            bookBean.setShelfName(ShelfName);
        }
        return source.bookListing(bookBeans,shelfCode,ShelfName);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> inventoryBook(List<BookBean> bookBeans, String currentShelfCode, String currentShelfName, int errorCount, int inshelfCount, int borrowCount, int notOnCount) {
        return source.inventoryBook(bookBeans, currentShelfCode, currentShelfName, errorCount, inshelfCount, borrowCount, notOnCount);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> parallelLogs(List<BookBean> bookBeans, String currentShelfCode, String currentShelfName, int errorCount, int inshelfCount, int borrowCount, int notOnCount) {
        return source.parallelLogs(bookBeans, currentShelfCode, currentShelfName, errorCount, inshelfCount, borrowCount, notOnCount);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> downBook(List<BookBean> bookBeans) {
        return source.downBook(bookBeans);
    }

    @Override
    public Observable<BaseBean<List<BookBean>>> getBookByKeyword(String keyword, Integer pageIndex, Integer pageSize) {
        return source.getBookByKeyword(keyword, pageIndex, pageSize);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> insertBookDeleteLogs(List<BookBean> bookBeans) {
        return source.insertBookDeleteLogs(bookBeans);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> removeOld(List<BookBean> bookBeans) {
        return source.removeOld(bookBeans);
    }

    @Override
    public Observable<BaseBean<List<ShelfBean>>> getShelfList(String shelfCode) {
        return source.getShelfList(shelfCode);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> updateFirstBook(List<ShelfBean> shelfBeans) {
        return source.updateFirstBook(shelfBeans);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> createupdatetask(String startcode, String endcode) {
        return source.createupdatetask(startcode,endcode);
    }

    @Override
    public Observable<BaseBean<BookCarBean>> getBookCarInfo(String carId) {
        return source.getBookCarInfo(carId);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> bindBook2Car(List<BookBean> beans, String carId) {
        return source.bindBook2Car(beans,carId);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> upBook2ShelfFromCar(List<BookBean> beans, String carId) {
        return source.upBook2ShelfFromCar(beans,carId);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> listingGuide(List<BookBean> beans) {
        return source.listingGuide(beans);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> changeShelf(List<BookBean> bookBeans, String shelfCode, String shelfName) {
        for (BookBean bean : bookBeans) {
            bean.setOldShelfCode(bean.getShelfCode());
            bean.setOldShelfName(bean.getShelfName());
            bean.setShelfCode(shelfCode);
            bean.setShelfName(shelfName);
        }
        return source.changeShelf(bookBeans, shelfCode,shelfName);
    }

    @Override
    public Observable<BaseBean<UpdateResult>> changeShelfLog(List<BookBean> bookBeans, String shelfCode) {
        return source.changeShelfLog(bookBeans, shelfCode);
    }

    @Override
    public Observable<BaseBean<List<ShelfBean>>> getErrorShelf(String startcode, String endcode) {
        return source.getErrorShelf(startcode, endcode);
    }

    @Override
    public Observable<BaseBean<RecordBean>> getUpdateRecordList(int finishstatus, int pageindex, int pagesize) {
        return source.getUpdateRecordList(finishstatus,pageindex,pagesize);
    }

    @Override
    public List<StructBean> getStructData() {
        return source.getStructData();
    }

    @Override
    public Observable<BaseBean<List<BookBean>>> getBookByShelfCode(String epc) {
        return source.getBookByShelfCode(epc);
    }

    @Override
    public Observable<BaseBean<List<BookBean>>> getBookByMultiShelf(String startCode, String endCode,String BookCountlimit) {
        return source.getBookByMultiShelf(startCode, endCode,BookCountlimit);
    }
}
